package com.qf.servlet;

import com.qf.pojo.Category;
import com.qf.service.CategoryService;
import com.qf.service.impl.CategoryServiceImpl;
import com.qf.utils.JsonUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 分类信息展示的控制器
 */
@WebServlet("/category")
public class CategoryServlet extends BaseServlet {

    /**
     * 获取所有分类列表
     * @param request 请求对象
     * @param response  响应对象
     */
    public void findAllCategory(HttpServletRequest request,HttpServletResponse response) throws IOException {

        //调用分类的业务接口
        CategoryService categoryService = new CategoryServiceImpl() ;
        List<Category> list = categoryService.getAllCategory();

        //需要将List集合转换成Json对象
        String jsonStr = JsonUtils.list2json(list);

        //响应给浏览器
        response.getWriter().write(jsonStr);

    }

}
